﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using LCA.Community.DAL.Model;
using Microsoft.Practices.Unity;
using LCA.Community.DAL.Interfaces;

namespace LCA.Community.Web.Models
{
    public class QuestionViewModel
    {
        public QuestionViewModel(Question question)
        {
            Question = question;
        }

        public static List<QuestionViewModel> ConvertQuestionsList(List<Question> questions)
        {
            var viewModels = new List<QuestionViewModel>();
            questions.ForEach(q => viewModels.Add(MvcApplication.Container.Resolve<QuestionViewModel>(new ParameterOverrides { { "question", q } })));

            return viewModels;
        }

        public List<AnswerViewModel> Answers
        {
            get
            {

                var answerViewModels = AnswerViewModel.ConvertAnswersList(AnswersRepository.GetAnswersByQuestion(Question.RowKey));
                return answerViewModels;
            }
        }

        public Question Question { get; set; }

        [Dependency]
        public IAnswersRepository AnswersRepository { get; set; }
    }
}